package com.ktmall.ktmalluijava.service.impl;

import com.ktmall.ktmalluijava.mapper.BannerMapper;
import com.ktmall.ktmalluijava.pojo.Banner;
import com.ktmall.ktmalluijava.service.BannerService;
import com.ktmall.ktmalluijava.utils.Page;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/5/14 上午8:35
 */
@Service
public class BannerServiceImpl implements BannerService {

    @Resource
    private BannerMapper bannerMapper;

    /**
     * 获取分页数据
     *
     * @param type
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public Page<Banner> getPage(Integer type, Integer pageNo, Integer pageSize) {
        Page<Banner> page = new Page<>();
        page.setPageSize(pageSize);
        page.setTotalCount(bannerMapper.count(type));
        page.setPageNo(pageNo);
        int offset = (page.getPageNo() - 1) * page.getPageSize();
        page.setData(bannerMapper.selectList(type, offset, pageSize));
        return page;
    }

    /**
     * 添加
     *
     * @param banner
     * @return
     */
    @Override
    public int add(Banner banner) {
        return bannerMapper.add(banner);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public int delete(Integer... id) {
        if(id.length==1){
            return bannerMapper.delete(id[0]);
        }
        int count = 0;
        for (Integer integer : id) {
            count+=bannerMapper.delete(integer);
        }
        return count;
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Override
    public Banner detail(Integer id) {
        return bannerMapper.detail(id);
    }

    /**
     * 更新
     *
     * @param banner
     * @return
     */
    @Override
    public int update(Banner banner) {
        return bannerMapper.update(banner);
    }
}
